﻿var textid = "ADM.PROFILESUMMARYTEXT";
var lovid = "ADM.PROFILESUMMARYINFOTYPE";

AddProfileSummary = function(){
    var btn = $id("btnAdd");
    var text = $id(textid);
    var lovh = $id("lovh_" + lovid);
    var load = $id("lnkdscd_Grid");
    
    text.style.backgroundColor = text.value == "" ? "#FFAAAA" : "#FFFFFF";
    
    if( text.value == "" || lovh.value == "" )
    {
        alert("Mohon lengkapi form");
        return false;
    }
    
    load.innerHTML = "<img src='" + LOADING.src + "' alt='' />";    cbkEditor_c.PerformCallback( "add" + DELIMITER + lovh.value + DELIMITER + text.value );
    
    btn.style.display = "none";
}

DeleteProfileSummary = function(id){
    if(confirm("Delete ProfileSummary?"))
    {
        cbkEditor_c.PerformCallback( "del" + DELIMITER + id );
    }
}

EditProfileSummary = function(id){
    var div = $id("popuplayer");
    div.style.display = "block";    div.innerHTML = "<img src='" + LOADING.src + "' alt='' />";    renderFirst();
    
    cbkEditor_c.PerformCallback("edit" + DELIMITER + id);
}

ToggleValidity = function(id){
    cbkEditor_c.PerformCallback( "toggle" + DELIMITER + id );
}

cbkEditor_c_CallbackComplete = function(e){
    var mode = e.parameter.split(DELIMITER)[0];
    
    if( mode == "add" )
    {
        var load = $id("lnkdscd_Grid");
        var btn = $id("btnAdd");

        load.innerHTML = "";
        
        if( e.result == "" )
        {
            var name = $id(textid);
            var lov = $id("lov_" + lovid);
            var lovh = $id("lovh_" + lovid);
            
            lovh.value = lov.value = name.value = "";    
        }
        
        btn.style.display = "";
        
        reloadGrid(e.result);
    }
    else if( mode == "edit" )
    {
        var div = $id("popuplayer");
        div.innerHTML = e.result;
    }
    else if( mode == "del" ){
        reloadGrid(e.result);        
    }
    else if( mode == "toggle" ){
        reloadGrid(e.result);        
    }
    else if( mode == "update" )
    {
        if( e.result == "" )
        {
            var div = $id("popuplayer");
            div.innerHTML = "";            div.style.display = "none";
        }
        else
        {
            var id = e.parameter.split(DELIMITER)[1];
            var btnCancel = $id("lnkdscd_" + id);
            var btnsave = $id("lnk_" + id);
            var load = $id("load_" + id);
            
            load.innerHTML = "";
            btnCancel.style.display = "";
            btnsave.style.display = "";
        }

        reloadGrid(e.result);
    }
}

closeEditor = function(){
    var div = $id("popuplayer");
    div.innerHTML = "";    div.style.display = "none";}

saveEditor = function(id){
    if(!confirm("save changes?"))
    {
        return;
    }
    var btnCancel = $id("lnkdscd_" + id);
    var btnsave = $id("lnk_" + id);
    var load = $id("load_" + id);
    
    var text = $id(textid + "_" + id);
    
    text.style.backgroundColor = text.value == "" ? "#FFAAAA" : "#FFFFFF";
    
    if( text.value == "" )
    {
        alert("Mohon lengkapi form");
        return false;
    }
    load.innerHTML = "<img src='" + LOADING.src + "' alt='' />";    
    cbkEditor_c.PerformCallback( "update" + DELIMITER + id + DELIMITER + text.value );
    
    btnCancel.style.display = "none";
    btnsave.style.display = "none";
}

reloadGrid = function(param)
{
    if( param == "" )
    {
        dgMain_c.PerformCallback();
    }
    else
    {
        alert(param);
    }
}

toggle = function (fsid)
{
    var div = $id("div_" + fsid);
    var lnk = $id("lnk_" + fsid);
    var lnkdscd = $id("lnkdscd_" + fsid);
    
    var display = "";
    
    if( div.style.display != "none" )
    {
        display = "none";
    }
    
    div.style.display = display;
    
    if( lnk != null )
    {
        lnk.style.display = display;
    }
    
    if( lnkdscd != null )
    {
        lnkdscd.style.display = display;
    }
}

StartLoadingAnimation = function(div){
    div.innerHTML = "<img src='" + LOADING.src + "' alt='' />";    
}

EndLoadingAnimation = function(div){
    div.innerHTML = "";    
}